﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using Portal.Code;

namespace Portal
{
    public partial class Default : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(IsPostBack) return;

            var ids = CategoryManager.GetTopHotCategories();
            var sb = new StringBuilder();
            using (var db = new CompanyDicContext())
            {
                foreach (var id in ids)
                {
                    var query =
                        db.Organizations.Where(p => p.CategoryId == id).OrderByDescending(p => p.TotalMark).Take(10).ToList();
                    var category = query.FirstOrDefault().Category;
                    sb.AppendFormat("<div class=\"rank_wrapper\">");
                    sb.AppendFormat("<a class=\"rank_icon float_left\" href=\"/List.aspx?Category={0}\">", id);
                    sb.AppendFormat("<img src=\"image/icon/category/category_{0}_44_44.png\" alt=\"\" />", category.Code);
                    sb.AppendFormat("</a><a class=\"topic_title\" href=\"/List.aspx?Category={0}\">", id);
                    sb.AppendFormat("<h3>{0}</h3></a>", category.Name + "排行榜");
                    sb.AppendFormat("<ul class=\"rank_list\">");
                    int index = 0;
                    foreach (var item in query)
                    {
                        sb.AppendFormat("<li><a href=\"Detail.aspx?Id={0}&Rank={1}\">{2}</a></li>", item.Id, ++index, item.Name);
                    }
                    sb.AppendFormat("</ul>");
                    sb.AppendFormat("<ul class=\"more_rank_info float_left\">");
                    sb.AppendFormat("<li><a href=\"/List.aspx?Category={0}&OrderBy={1}\">更多</a></li>", id, 1);
                    sb.AppendFormat("<li><a href=\"/List.aspx?Category={0}&OrderBy={1}\">红榜</a></li>", id, 1);
                    sb.AppendFormat("<li><a href=\"/List.aspx?Category={0}&OrderBy={1}\">黑榜</a></li>", id, 2);
                    sb.AppendFormat("<li><a href=\"/List.aspx?Category={0}&OrderBy={1}\">热度</a></li>", id, 3);
                    sb.AppendFormat("</ul><div class=\"clear_float\"></div></div>");
                }
                litContent.Text = sb.ToString();
            }
        }
    }
}